package com.woniuxy.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.controller.form.PriorityForm;
import com.woniuxy.controller.form.SeverityForm;
import com.woniuxy.controller.info.PriorityInfo;
import com.woniuxy.controller.info.SeverityInfo;
import com.woniuxy.controller.info.UserInfo;
import com.woniuxy.model.Defectpriority;
import com.woniuxy.model.Defectseverity;
import com.woniuxy.service.DefectpriorityService;
import com.woniuxy.service.DefectseverityService;
import com.woniuxy.utils.MyException;
import com.woniuxy.utils.Result;
import com.woniuxy.utils.TimeMethodsutil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 马世亮
 * @since 2022-02-15
 */
@RestController
@Api(tags = "严重程度接口")
@RequestMapping("/defectseverity")
public class DefectseverityController {

    @Resource
    private DefectseverityService defectseverityService;

    /**
     * 查询严重程度
     * @return
     */
    @PostMapping("/findAll")
    @ApiOperation("查询严重程度")
    public Result findAll(){
        List<SeverityInfo> all = defectseverityService.findAll();

        return Result.success(200,"success",all);
    }

    /**
     * 描述：新增严重程度
     * @return num
     */
    @ApiOperation("新增严重程度")
    @PostMapping("/addSeverity")
    public Result addPriority(@RequestBody SeverityForm severityForm) throws MyException {

        Integer add= defectseverityService.add(severityForm);
        if(add>0){
            return Result.success(200,"success",add);
        }else{
            throw new MyException(405,"新增失败");
        }

    }


    /**
     * 描述：批量删除
     * @return delectid
     */
    @ApiOperation("批量删除")
    @PostMapping("/delectMany")
    public Result delectMany(@RequestBody List<Integer> ids) {
        System.out.println("================" + ids);

        Integer delectid = defectseverityService.delectByIds(ids);
        return Result.success(200, "success", delectid);
    }

    /**
     * 单个删除
     * @param defectseverityId
     * @return
     * @throws MyException
     */
    @ApiOperation("单个删除")
    @PostMapping("/delectbyid/{defectseverityId}")
    public  Result delectByid(@PathVariable Integer defectseverityId) throws MyException {



        boolean b = defectseverityService.removeById(defectseverityId);
        if (b){
            return Result.success(200,"success",b);
        }else {
            throw new MyException(405,"删除失败");
        }

    }

    /**
     * 修改严重程度
     * @param severityForm
     * @return
     * @throws MyException
     */
    @ApiOperation("修改严重程度")
    @PostMapping("/update")
    public Result updatePriority(@RequestBody SeverityForm severityForm) throws MyException {

        boolean change = defectseverityService.change(severityForm);

        if (change){
            return Result.success(200,"success",change);
        }else {
            throw new MyException(405,"服务器繁忙");
        }
    }

    /**
     * 修改状态
     * @param severityForm
     * @return
     */
    @ApiOperation("修改状态")
    @PostMapping("/changeState")
    public Result changeState(@RequestBody SeverityForm severityForm){
        Integer integer = defectseverityService.changeState(severityForm);
        return Result.success(200,"success",integer);
    }
}

